<?php
/**
 * Created by PhpStorm.
 * User: 17208
 * Date: 2020/9/28
 * Time: 16:08
 */
namespace app\controller;

use app\server\ServerTaoBao;
use app\server\ServerWeChat;
use app\server\taobao\ErrorCode;
use extend\Log;

class Wechat
{
    private $logger;
    public function __construct( )
    {
        $this->logger = Log::getInstance('wechat');
    }

    public function index(){
        try{
            $post_data = json_decode(file_get_contents('php://input'),true);
            // 日志记录
            $this->logger->info(json_encode([
                "get"=>$_GET,
                "post"=>$post_data,
                "files"=>$_FILES
            ]));

            ServerWeChat::replyMessage();

        }catch (\Exception $e){
            // 日志记录
            $this->logger->error($e->getMessage());
            echo $e->getMessage();
            exit();
        }
    }
    public function test(){
        $a = ServerWeChat::matchingContent($_GET['a']);
        list($code,$message) = ServerTaoBao::parseTkl2Url($_GET['a']);
        switch ($code){
            case -1: $a = '系统维护中！';break;
            case 2: $a = ErrorCode::$errorMsg[ErrorCode::$noCoupon];break;
            default: $a = $message;break;
        }
        echo $a;die;
    }
}